package Arrays;

public class _605_CanPlaceFlowers {
    public boolean canPlaceFlowers(int[] flowerbed, int n) {
        if (n == 0) {
            return true;
        }
        if (flowerbed.length == 1) {
            return flowerbed[0]==0?true:false;
        }
        int count = n;
        for(int i=0;i<flowerbed.length;i++) {
            if (flowerbed[i]==0) {
                if (i == 0) {
                    if (flowerbed[i + 1] == 0) {
                        flowerbed[i] = 1;
                        count--;
                    }
                }else if (i == flowerbed.length - 1) {
                    if (flowerbed[i - 1] == 0) {
                        flowerbed[i] = 1;
                        count--;
                    }
                } else {
                    if (flowerbed[i + 1] == 0 && flowerbed[i - 1] == 0) {
                        flowerbed[i] = 1;
                        count--;
                    }
                }
            }
        }
        return count<=0?true:false;
    }
}
